package com.kmxd.ams.core.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 创建Swagger配置
 * @author ZuoLG
 */
@Configuration
public class SwaggerConfiguration {

  @Bean
  public GroupedOpenApi allAPi() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller"};
    return GroupedOpenApi.builder()
        .group("全部")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi jyCheck() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.jy"};
    return GroupedOpenApi.builder()
            .group("借阅模块")
            .pathsToMatch(paths)
            .packagesToScan(packagedToMatch)
            .build();
  }

  @Bean
  public GroupedOpenApi sxCheck() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.sx"};
    return GroupedOpenApi.builder()
        .group("四性检测")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi oss() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.oss"};
    return GroupedOpenApi.builder()
        .group("Oss文件")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi flow() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.flowable"};
    return GroupedOpenApi.builder()
        .group("流程管理")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi dashboard() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.dashboard"};
    return GroupedOpenApi.builder()
        .group("仪表台")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi receive() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.receive"};
    return GroupedOpenApi.builder()
        .group("档案接收")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi arrange() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.arrange"};
    return GroupedOpenApi.builder()
        .group("档案整理")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi preserve() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.preserve"};
    return GroupedOpenApi.builder()
        .group("档案保存")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi use() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.use"};
    return GroupedOpenApi.builder()
        .group("档案利用")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi handle() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.handle"};
    return GroupedOpenApi.builder()
        .group("档案处置")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi statistics() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.statistics"};
    return GroupedOpenApi.builder()
        .group("档案统计")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi archive() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.archive"};
    return GroupedOpenApi.builder()
        .group("档案配置")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi i18nApi() {
    String[] paths = {"/i18n/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.i18n"};
    return GroupedOpenApi.builder()
        .group("多语言")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi sysApi() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.system"};
    return GroupedOpenApi.builder()
        .group("System-系统模块")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public GroupedOpenApi userApi() {
    String[] paths = {"/**"};
    String[] packagedToMatch = {"com.kmxd.ams.controller.system.login"};
    return GroupedOpenApi.builder()
        .group("User-用户模块")
        .pathsToMatch(paths)
        .packagesToScan(packagedToMatch)
        .build();
  }

  @Bean
  public OpenAPI customOpenAPI() {
    return new OpenAPI()
        .info(
            new Info()
                .title("AMS 数字档案管理系统接口文档")
                .version("1.0")
                .description("AMS 数字档案管理系统接口文档")
                .termsOfService("http://doc.kmxd.com")
                .license(new License().name("Apache 2.0").url("http://doc.xiaominfo.com")));
  }
}
